<?php

namespace app\admin\controller;


use app\admin\model\User;

/**
 * 会员
 * Class Home
 * @package app\admin\controller
 */
class Users extends Base
{

    //会员列表
    public function userList(){
        $User = new User();
        $keyword = input("keyword/s");
        if(input("?table")) {
            $result["code"] = 0;
            $result["data"] = $User->userList($keyword);
            $result["count"] = $User->userListCount($keyword);
        }
        return !empty($result) ? json($result) : view('userList',[
            'title'                 =>  '会员列表',
        ]);
    }

    //修改密码
    public function editPassword(){
        $user_id = input("user_id/d",0);
        $User = new User();
        if(!empty($user_id)){
            $data = input("post.");
            $msg = $User->checkData($data,[
                ["password", "require","密码不能为空"],
            ]);
            if($msg === true) {
                if ($User->mySave($data, "user_id", $user_id)) {
                    $result["code"] = 0;
                    $result["msg"] = "操作成功!";
                } else {
                    $result["code"] = 10000;
                    $result["msg"] = "操作失败！";
                }
            }else{
                $result["code"] = 1;
                $result["msg"] = $msg;
            }
        }else{
            $result["code"] = 1;
            $result["msg"] = "user_id参数为空!";
        }
        return json($result);
    }

    //解除冻结
    public function unfreezing(){
        $user_id = input("user_id/d",0);
        $User = new User();
        if(!empty($user_id)){
            if ($User->mySave(["is_frozen"=>0], "user_id", $user_id)) {
                $result["code"] = 0;
                $result["msg"] = "操作成功!";
            } else {
                $result["code"] = 10000;
                $result["msg"] = "操作失败！";
            }
        }else{
            $result["code"] = 1;
            $result["msg"] = "user_id参数为空!";
        }
        return json($result);
    }

    //个人信息
    public function userInfo(){
        $user_id = input("user_id/d",0);
        $User = new User();
        $userInfo = $User->PkInfo($user_id);
        return  view('userInfo',[
            'title'                 =>  '个人信息',
            'userInfo'              =>  $userInfo,
        ]);
    }
}